Imports System.IO
Imports System.IO.Compression
Imports WinCommander.FileSystemImageList

Public Class MainForm
    Public ItemTable As New DataTable
    Public ActiveView As ListView
    Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim v As ListView
        For i As Integer = 1 To 2
            If i = 1 Then v = LeftView Else v = RightView
            v.Columns.Add("Tên", 120, HorizontalAlignment.Left)
            v.Columns.Add("Mở rộng", 50, HorizontalAlignment.Right)
            v.Columns.Add("Kích thước", 50, HorizontalAlignment.Right)
            v.Columns.Add("Thời gian", 120, HorizontalAlignment.Right)
            v.Items.Clear()
            v.FullRowSelect = True
            v.View = View.Details
        Next
        'Create table for sorting
        ItemTable.Columns.Add("Name")
        ItemTable.Columns.Add("Ext")
        ItemTable.Columns.Add("Size")
        ItemTable.Columns.Add("Time")
        ItemTable.Columns.Add("FullPath")

        'Get Drive
        For Each Drive As DriveInfo In My.Computer.FileSystem.Drives
            If Drive.IsReady Then
                tscLeftDrive.Items.Add(String.Format("{0} - {1}", Drive.Name, Drive.VolumeLabel))
                tscRightDrive.Items.Add(String.Format("{0} - {1}", Drive.Name, Drive.VolumeLabel))
            End If
        Next
        tscLeftDrive.SelectedIndex = 0
        tscRightDrive.SelectedIndex = 0

        lbPath.Text = Application.StartupPath & ">"

        AddHandler LeftView.KeyDown, AddressOf ListView_KeyDown
        AddHandler RightView.KeyDown, AddressOf ListView_KeyDown

        AddHandler LeftView.GotFocus, AddressOf ListView_GotFocus
        AddHandler RightView.GotFocus, AddressOf ListView_GotFocus

        AddHandler LeftView.ItemActivate, AddressOf ListView_ItemActivate
        AddHandler RightView.ItemActivate, AddressOf ListView_ItemActivate

        AddHandler LeftView.SelectedIndexChanged, AddressOf ListView_SelectedIndexChanged
        AddHandler RightView.SelectedIndexChanged, AddressOf ListView_SelectedIndexChanged


        LeftView.Focus()

    End Sub


    Public Sub LoadFolderAndFiles(ByVal rootPath As String, ByVal view As ListView, Optional ByVal sortBy As SortColumn = SortColumn.isName, Optional ByVal FilterMark As String = "*.*")
        view.Items.Clear()

        Dim item As ListViewItem

        Dim folders As String() = IO.Directory.GetDirectories(rootPath, FilterMark)
        Dim files As String() = IO.Directory.GetFiles(rootPath, FilterMark)

        Dim FileSystemImages As New FileSystemImageList
        view.SmallImageList = FileSystemImages.SmallImageList

        item = New ListViewItem("[..]")
        item.ImageIndex = FileSystemImageList.FolderOpenIconIndex
        item.Tag = rootPath
        view.Items.Add(item)

        ItemTable.Rows.Clear()
        For Each folder As String In folders
            'Get Folder Information            
            Dim DirInfo As DirectoryInfo = New DirectoryInfo(folder)
            Dim ext As String = DirInfo.Extension
            Dim createDate As String = DirInfo.CreationTime
            Dim r As DataRow = ItemTable.NewRow
            r("Name") = IO.Path.GetFileNameWithoutExtension(folder)
            r("Ext") = ext
            r("Size") = ""
            r("Time") = createDate
            r("FullPath") = folder
            ItemTable.Rows.Add(r)
        Next

        If sortBy <> SortColumn.isUnsort Then ItemTable.DefaultView.Sort = ItemTable.Columns(sortBy).ColumnName

        'Now add to list view
        For Each r As DataRowView In ItemTable.DefaultView
            Dim FolderName As String = r("Name")
            item = New ListViewItem(FolderName)
            item.Tag = r("FullPath")
            item.ImageIndex = FileSystemImageList.FolderClosedIconIndex
            item.SubItems.Add(r("Ext"))
            item.SubItems.Add(r("Size"))
            item.SubItems.Add(r("Time"))
            view.Items.Add(item)
        Next

        'Now Process File
        ItemTable.Rows.Clear()
        For Each fileName As String In files
            'Get File Information
            Dim fInfo As FileInfo = New FileInfo(fileName)
            Dim ext As String = fInfo.Extension
            Dim Size As String = fInfo.Length \ 1000
            Dim createDate As String = fInfo.CreationTime
            Dim r As DataRow = ItemTable.NewRow
            r("Name") = IO.Path.GetFileName(fileName)
            r("Ext") = ext
            r("Size") = Size
            r("Time") = createDate
            r("FullPath") = fileName
            ItemTable.Rows.Add(r)

        Next

        If sortBy <> SortColumn.isUnsort Then ItemTable.DefaultView.Sort = ItemTable.Columns(sortBy).ColumnName

        'Now add to list view
        For Each r As DataRowView In ItemTable.DefaultView
            Dim FileName As String = r("Name")
            item = New ListViewItem(FileName)
            item.ImageIndex = FileSystemImages.GetTheFileIconIndex(FileName)
            item.Tag = r("FullPath")
            item.SubItems.Add(r("Ext"))
            item.SubItems.Add(r("Size"))
            item.SubItems.Add(r("Time"))
            view.Items.Add(item)
        Next

        If view Is LeftView Then
            tsLeftStatusBar.Text = String.Format("Total {0}  Folders/ {1} Files", folders.Length, files.Length)
        Else
            tsRightStatusBar.Text = String.Format("Total {0}  Folders/ {1} Files", folders.Length, files.Length)
        End If

        view.Tag = rootPath
        If view Is ActiveView Then lbPath.Text = ActiveView.Tag & ">"

    End Sub

    Private Sub ListView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
        Select Case e.KeyCode

            Case Keys.Oemplus

            Case Keys.Insert
                Dim v As ListView = sender
                For i As Integer = 0 To v.SelectedItems.Count - 1
                    Dim item As ListViewItem = v.SelectedItems(i)
                    If item.ForeColor = Color.Black Then
                        item.ForeColor = Color.Red
                        item.Font = New Font(Me.Font, FontStyle.Bold)
                    Else
                        item.ForeColor = Color.Black
                        item.Font = Me.Font
                    End If
                Next
        End Select
    End Sub


    Private Sub ListView_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs)
        ActiveView = sender
        lbPath.Text = ActiveView.Tag & ">"

    End Sub

    Private Sub ListView_ItemActivate(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim item As ListViewItem = sender.FocusedItem
        If item.Tag IsNot Nothing Then
            Select Case item.ImageIndex
                Case FileSystemImageList.FolderClosedIconIndex
                    LoadFolderAndFiles(item.Tag, sender)
                    Directory.SetCurrentDirectory(sender.Tag)
                    lbPath.Text = sender.Tag & ">"
                Case FileSystemImageList.FolderOpenIconIndex
                    Dim parentFolder As DirectoryInfo = IO.Directory.GetParent(item.Tag)
                    If parentFolder IsNot Nothing Then
                        LoadFolderAndFiles(parentFolder.FullName, sender)
                        Directory.SetCurrentDirectory(sender.Tag)
                        lbPath.Text = sender.Tag & ">"
                    End If
                Case Else
                    'File select
                    Try
                        Process.Start(item.Tag)
                    Catch ex As Exception
                        MsgBox("Can not open file")
                    End Try
            End Select
        End If
    End Sub

    Private Sub ListView_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim item As ListViewItem = sender.FocusedItem
        If item.Tag IsNot Nothing Then
            LabelStatusBar.Text = item.Tag

        End If
    End Sub


    Private Sub tscLeftDrive_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscLeftDrive.SelectedIndexChanged
        Dim drive As DriveInfo = My.Computer.FileSystem.Drives(sender.SelectedIndex)
        LoadFolderAndFiles(drive.Name, LeftView)
        Dim FreeSpace As String = Format(drive.TotalFreeSpace \ 1000000, "###,###,###")
        Dim UsedSpace As String = Format((drive.TotalSize - drive.TotalFreeSpace) \ 1000000, "###,###,###")
        tsLeftDriveStatus.Text = String.Format("{0}M Free - {1}M Used", FreeSpace, UsedSpace)
    End Sub
    Private Sub tscRightDrive_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tscRightDrive.SelectedIndexChanged
        Dim drive As DriveInfo = My.Computer.FileSystem.Drives(sender.SelectedIndex)
        LoadFolderAndFiles(drive.Name, RightView)
        Dim FreeSpace As String = Format(drive.TotalFreeSpace \ 1000000, "###,###,###")
        Dim UsedSpace As String = Format((drive.TotalSize - drive.TotalFreeSpace) \ 1000000, "###,###,###")
        tsRightDriveStatus.Text = String.Format("{0}M Free - {1}M Used", FreeSpace, UsedSpace)
    End Sub

    Private Sub tsGridLine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsGridLine.Click
        LeftView.GridLines = Not LeftView.GridLines
        RightView.GridLines = Not RightView.GridLines
    End Sub

    Private Sub tsNotePad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsNotePad.Click
        Process.Start("Notepad.exe")
    End Sub

    Private Sub tsCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsCalc.Click
        Process.Start("Calc.exe")
    End Sub

    Private Sub tsHelp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsHelp.Click
        mnAbout_Click(Nothing, Nothing)
    End Sub

    Private Sub tsRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsRefresh.Click
        If ActiveView IsNot Nothing Then
            LoadFolderAndFiles(ActiveView.Tag, ActiveView)
        End If
    End Sub

    Private Sub tsUpFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsUpFolder.Click
        If ActiveView IsNot Nothing Then
            Dim parentFolder As DirectoryInfo = IO.Directory.GetParent(ActiveView.Items(0).Tag)
            If parentFolder IsNot Nothing Then
                LoadFolderAndFiles(parentFolder.FullName, ActiveView)
            End If
        End If
    End Sub

    Private Sub txtCommand_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtCommand.KeyUp
        Select Case e.KeyCode
            Case Keys.Enter
                ' Set start information.
                Dim start_info As New ProcessStartInfo("cmd.exe")
                start_info.Arguments = "/c" & txtCommand.Text
                start_info.UseShellExecute = False
                start_info.CreateNoWindow = True
                start_info.RedirectStandardOutput = True
                start_info.RedirectStandardError = True

                ' Make the process and set its start information.
                Dim proc As New Process()
                proc.StartInfo = start_info

                ' Start the process.
                proc.Start()

                ' Attach to stdout and stderr.
                Dim std_out As StreamReader = proc.StandardOutput()
                Dim std_err As StreamReader = proc.StandardError()

                ' Display the results.

                DOSForm.txtResult.Text = std_out.ReadToEnd()
                Dim sError As String = std_err.ReadToEnd()
                DOSForm.txtResult.AppendText(sError)

                If DOSForm.txtResult.Text <> "" Then DOSForm.Show()

                ' Clean up.
                std_out.Close()
                std_err.Close()
                proc.Close()
        End Select
    End Sub

    Private Sub mnLeftOnOf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftOnOf.Click
        Me.SplitContent.Panel1Collapsed = Not Me.SplitContent.Panel1Collapsed
    End Sub

    Private Sub mnLeftBrieft_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftBrieft.Click
        Me.LeftView.View = View.List
    End Sub

    Private Sub mnLeftFull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftFull.Click
        Me.LeftView.View = View.Details
    End Sub

    Private Sub mnLeftRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftRefresh.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView)
    End Sub

    Private Sub mnLeftUnsort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftUnsort.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isUnsort)
    End Sub


    Private Sub LeftView_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles LeftView.ColumnClick
        LoadFolderAndFiles(LeftView.Tag, LeftView, e.Column)
    End Sub

    Public Enum SortColumn
        isName = 0
        isExt = 1
        isSize = 2
        isTime = 3
        isUnsort = 4
    End Enum

    Private Sub mnLeftName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftName.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isName)
    End Sub

    Private Sub mnLeftExt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftExt.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isExt)
    End Sub

    Private Sub mnLeftTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftTime.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isTime)
    End Sub

    Private Sub mnLeftSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnLeftSize.Click
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isSize)
    End Sub

    Private Sub mnView_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnView.Click
        Process.Start("notepad", ActiveView.FocusedItem.Tag)
    End Sub

    Private Sub mnEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnEdit.Click
        Process.Start(ActiveView.FocusedItem.Tag)
    End Sub

    Private Sub mnFind_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnFind.Click
        Dim FilterMark As String = InputBox("File mark", "Find File", "")
        If FilterMark <> "" Then
            LoadFolderAndFiles(ActiveView.Tag, ActiveView, SortColumn.isName, FilterMark)
        End If
    End Sub

    Private Sub mnCompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnCompare.Click
        CompareLeftRightFolders()
    End Sub

    Private Sub SelectAll(ByVal isAll As Boolean)
        For Each item As ListViewItem In ActiveView.Items
            If isAll Then
                item.ForeColor = Color.Red
                item.Font = New Font(Me.Font, FontStyle.Bold)
            Else
                item.ForeColor = Color.Black
                item.Font = Me.Font
            End If
        Next
    End Sub

    Private Sub CompareLeftRightFolders()
        LoadFolderAndFiles(LeftView.Tag, LeftView, SortColumn.isName)
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isName)
        For Each LeftItem As ListViewItem In LeftView.Items
            Dim item As ListViewItem = RightView.FindItemWithText(LeftItem.Text)
            If item Is Nothing Then
                LeftItem.ForeColor = Color.DarkRed
                LeftItem.Font = New Font(Me.Font, FontStyle.Bold)
            End If
        Next

        For Each RightItem As ListViewItem In RightView.Items
            Dim item As ListViewItem = LeftView.FindItemWithText(RightItem.Text)
            If item Is Nothing Then
                RightItem.ForeColor = Color.DarkRed
                RightItem.Font = New Font(Me.Font, FontStyle.Bold)
            End If
        Next

    End Sub

    Private Sub mnSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnSelectAll.Click
        SelectAll(True)
    End Sub

    Private Sub mnDeselectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnDeselectAll.Click
        SelectAll(False)
    End Sub

    Private Sub mnRightOnOf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightOnOf.Click
        Me.SplitContent.Panel1Collapsed = Not Me.SplitContent.Panel1Collapsed
    End Sub

    Private Sub mnRightBrief_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightBrief.Click
        Me.RightView.View = View.List
    End Sub

    Private Sub mnRightFull_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightFull.Click
        Me.RightView.View = View.Details
    End Sub

    Private Sub mnRightRefresh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightRefresh.Click
        LoadFolderAndFiles(RightView.Tag, RightView)
    End Sub

    Private Sub mnRightUnsort_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightUnsort.Click
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isUnsort)
    End Sub

    Private Sub mnRightName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightName.Click
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isName)
    End Sub

    Private Sub mnRightExt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightExt.Click
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isExt)
    End Sub

    Private Sub mnRightTime_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightTime.Click
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isTime)
    End Sub

    Private Sub mnRightSize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnRightSize.Click
        LoadFolderAndFiles(RightView.Tag, RightView, SortColumn.isSize)
    End Sub

    Private Sub ZipFile(ByVal source As String, ByVal Dest As String)
        Dim fsWrite As New FileStream(Dest, FileMode.Create)
        Dim zipStream As New GZipStream(fsWrite, CompressionMode.Compress)
        Dim Writer As New StreamWriter(zipStream)
        Writer.Write(My.Computer.FileSystem.ReadAllBytes(source))
        Writer.Flush()
        zipStream.Flush()
        fsWrite.Close()
    End Sub
    Private Sub UnZipFile(ByVal source As String, ByVal Dest As String)
        Dim fsRead As New FileStream(source, FileMode.Open)
        Dim UnZipStream As New GZipStream(fsRead, CompressionMode.Decompress)
        Dim TotalByte As Long = fsRead.Length
        Dim buff(TotalByte) As Byte
        fsRead.Read(buff, 0, buff.Length)
        fsRead.Close()
        My.Computer.FileSystem.WriteAllBytes(Dest, buff, False)
    End Sub


    Private Sub mnZip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnZip.Click
        'Get selected file
        Select Case ActiveView.FocusedItem.ImageIndex
            Case FileSystemImageList.FolderClosedIconIndex, FileSystemImageList.FolderOpenIconIndex
                'Do not zip folder
                MsgBox("Zip Folder Not Support")
            Case Else
                Dim sourceFile As String = ActiveView.FocusedItem.Tag
                Dim DestFolder As String = LeftView.Tag
                If ActiveView Is LeftView Then DestFolder = RightView.Tag
                Dim DestFile As String = DestFolder & IO.Path.GetFileNameWithoutExtension(sourceFile)
                DestFile = InputBox("Zip File To", "Zip", DestFile & ".zip")
                If DestFile <> "" Then
                    ZipFile(sourceFile, DestFile)
                    'Refresh Folder
                    LoadFolderAndFiles(RightView.Tag, RightView)
                    LoadFolderAndFiles(LeftView.Tag, LeftView)
                End If
        End Select
    End Sub

    Private Sub mnUnZip_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnUnZip.Click
        'Get selected file
        Select Case ActiveView.FocusedItem.ImageIndex
            Case FileSystemImageList.FolderClosedIconIndex, FileSystemImageList.FolderOpenIconIndex
                'Do not zip folder
                MsgBox("Zip Folder Not Support")
            Case Else
                Dim sourceFile As String = ActiveView.FocusedItem.Tag
                Dim DestFolder As String = LeftView.Tag
                If ActiveView Is LeftView Then DestFolder = RightView.Tag
                Dim DestFile As String = DestFolder & IO.Path.GetFileNameWithoutExtension(sourceFile)
                DestFile = InputBox("UnZip File To", "UnZip", DestFile)
                If DestFile <> "" Then
                    UnZipFile(sourceFile, DestFile)
                    'Refresh Folder
                    LoadFolderAndFiles(RightView.Tag, RightView)
                    LoadFolderAndFiles(LeftView.Tag, LeftView)
                End If
        End Select
    End Sub

    Private Sub mnTree_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnTree.Click
        TreeForm.RootFolder = ActiveView.Tag
        TreeForm.FormParent = Me
        TreeForm.Show()
    End Sub

    Private Sub tsExecute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsExecute.Click
        mnEdit_Click(Nothing, Nothing)
    End Sub

    Private Sub tsTreeSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tsTreeSearch.Click
        mnTree_Click(Nothing, Nothing)
    End Sub

    Private Sub mnAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnAbout.Click
        MsgBox("WinCommander .NET Demo - Minh khai Book")
    End Sub


    Private Sub FileAction(ByVal action As String)
        'Get selected file or folder
        Dim isSelectFolder As Boolean = False

        Dim TargetView As ListView = LeftView
        If ActiveView Is LeftView Then TargetView = RightView

        Dim sourceFolder As String = ActiveView.Tag
        Dim targetFolder As String = TargetView.Tag
        Dim selectFolder As String = ""

        Dim sourceFile As String = ""
        Dim targetFile As String = ""

        Try
            For Each item As ListViewItem In ActiveView.SelectedItems
                Select Case item.ImageIndex
                    Case FileSystemImageList.FolderClosedIconIndex
                        isSelectFolder = True
                        selectFolder = IO.Path.GetFileName(item.Tag)
                    Case Else
                        sourceFile = item.Tag
                        targetFile = targetFolder & "\" & IO.Path.GetFileName(sourceFile)
                End Select

                Select Case action
                    Case "Copy"
                        If isSelectFolder Then
                            My.Computer.FileSystem.CopyDirectory(sourceFolder & selectFolder, targetFolder & selectFolder)
                        Else
                            My.Computer.FileSystem.CopyFile(sourceFile, targetFile)
                        End If

                    Case "Rename"
                        Dim NewName As String
                        If isSelectFolder Then
                            NewName = InputBox("Enter new folder:", "Rename", targetFolder & selectFolder)
                            If NewName <> "" Then
                                My.Computer.FileSystem.RenameDirectory(sourceFolder & selectFolder, NewName)
                            End If
                        Else
                            NewName = InputBox("Enter new name:", "Rename", sourceFile)
                            If NewName <> "" Then
                                My.Computer.FileSystem.RenameFile(sourceFile, NewName)
                            End If
                        End If

                    Case "Move"
                        Dim NewName As String
                        If isSelectFolder Then
                            NewName = InputBox("Move to:", "Move", targetFolder & selectFolder)
                            If NewName <> "" Then
                                My.Computer.FileSystem.MoveDirectory(sourceFolder & selectFolder, NewName)
                            End If
                        Else
                            NewName = InputBox("Move to:", "Move", targetFile)
                            If NewName <> "" Then
                                My.Computer.FileSystem.RenameFile(sourceFile, NewName)
                            End If
                        End If
                    Case "Delete"
                        If isSelectFolder Then
                            If MsgBox("Delete Folder " & sourceFolder & selectFolder & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                                My.Computer.FileSystem.DeleteDirectory(sourceFolder & selectFolder, FileIO.DeleteDirectoryOption.DeleteAllContents)
                            End If
                        Else
                            If MsgBox("Delete File " & sourceFile & "?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
                                My.Computer.FileSystem.DeleteFile(sourceFile)
                            End If
                        End If
                    Case "CreateFolder"
                        Dim NewFolder As String = InputBox("New Folder Name", "Create", "")
                        If NewFolder <> "" Then
                            My.Computer.FileSystem.CreateDirectory(sourceFolder & NewFolder)
                        End If
                End Select

            Next

            LoadFolderAndFiles(ActiveView.Tag, ActiveView)
            LoadFolderAndFiles(TargetView.Tag, TargetView)

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
        FileAction("Copy")
    End Sub

    Private Sub btnMove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMove.Click
        FileAction("Move")
    End Sub

    Private Sub btnNewFolder_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNewFolder.Click
        FileAction("CreateFolder")
    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
        FileAction("Delete")
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub


    Private Sub RightView_ColumnClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ColumnClickEventArgs) Handles RightView.ColumnClick
        LoadFolderAndFiles(RightView.Tag, LeftView, e.Column)
    End Sub

    Private Sub RightView_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RightView.SelectedIndexChanged

    End Sub
End Class
